# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import unittest, time

class Hao123(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.hao123.com"
        self.verificationErrors = []
    
    def test_Hao123(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.maximize_window()
        time.sleep(3)

        driver.find_element_by_id("mailUserName").clear()
        driver.find_element_by_id("mailUserName").send_keys("spring292713")
        time.sleep(2)
        driver.find_element_by_css_selector("label.js_selectLabel.mailselect").click()
#        driver.find_element_by_xpath("//ul[@id='mail_list']/li[@dn='5']").click()
        driver.find_element_by_xpath("//ul[@id='mail_list']/li[text()='@sohu.com']").click()
        driver.find_element_by_id("mailPassWord").clear()
        time.sleep(2)
        driver.find_element_by_id("mailPassWord").send_keys("zcx292713")
        time.sleep(2)
        driver.find_element_by_id("mailsubmit").click()
    
    def is_element_present(self, how, what):
        driver = self.driver
        win = driver.window_handles()         #获得当前窗口的句柄
        driver.switch_to_window(win)          #切换标签页
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException: return False
        return True
    
    def tearDown(self):
        time.sleep(5)
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
